<?php
/**
 * 个人中心模型
 */
namespace app\api\modules\v1\owner\models;

use app\api\components\ApiModel;
use Yii;
use app\models\base\Activity;

class Owner extends ApiModel
{
	public static function getvalues($user_id,$status)
	{
		$all_value = 0;
		$all_gold = 0;
		$all_cost = 0;
		//今天的起始时间
		$start_time = mktime(0,0,0,date('m'),date('d'),date('y'));
		$end_time = mktime(0,0,0,date('m'),date('d'),date('y'))+24*3600-1;
		$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
		$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
		$dayOfWeek = date('w')==0?7:date('w');
		$beginThisyear = mktime(0,0,0,1,1,date('y'));
		$endThisyear = mktime(23,59,59,12,31,date('y'));
		switch ($status) {
			case 1://今天
				$time = [$start_time,$end_time];
				break;
			case 2://本周
				$time = [$start_time-($dayOfWeek-1)*24*3600,$end_time];
				break;
			case 3://本月
				$time = [$beginThismonth,$endThismonth];
				break;
			case 4://本年
				$time = [$beginThisyear,$endThisyear];
				break;
			default:
				$time = [];
				break;
		}
		$activity = Activity::find()->where(['handler_user_id'=>$user_id,'status'=>5])
						->andWhere([
								'and',	
								['>=','review_time',$time[0]],
								['<','review_time',$time[1]]
							])
						->all();
		foreach ($activity as $k => $v) {
			$all_value += $v['surplus_value'];
			$all_gold += $v['surplus_gold'];
			$all_cost += $v['all_cost'];
		}
		$arr['all_value'] = round($all_value/8,1);
		$arr['all_gold'] = round($all_gold/8,1);
		$arr['all_cost'] = round($all_cost/8,1);
		return $arr;
	}
}